package com.tim.app.ui.adapter.someone_homepage;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.util.TimeUtil;
import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Problem;

import java.util.List;


/**
 * 问题列表的适配器
 */
public class HomepageQuestionAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, Problem> {

    private Context mContext;

    public HomepageQuestionAdapter(Context mContext, List<Problem> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new InfoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_homepage_question, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder mHolder, final int position, final Problem data) {
        if (data == null) {
            return;
        }

        if (null == data)
            return;
        final InfoViewHolder holder = (InfoViewHolder) mHolder;

        if (!TextUtils.isEmpty(data.getTitle())) {
            holder.tvAnswerQuestion.setText(data.getTitle());
        }
        holder.tvQuestionAnswerNumber.setText(mContext.getString(R.string.homepageQuestionAnswerNumber, String.valueOf(data.getAnswerCount())));
        holder.tvQuestionFollowNumber.setText(mContext.getString(R.string.homepageQuestionFollowNumber,String.valueOf(data.getConcernCount())));
        holder.tvPublishTime.setText(TimeUtil.formatTimeRuleOne(mContext, data.getCreateTime()));
    }


    public class InfoViewHolder extends BaseRecyclerViewHolder {

        TextView tvAnswerQuestion;
        TextView tvQuestionAnswerNumber;
        TextView tvQuestionFollowNumber;
        TextView tvPublishTime;

        public InfoViewHolder(View itemView) {
            super(itemView);
            tvAnswerQuestion = (TextView) itemView.findViewById(R.id.tvAnswerQuestion);
            tvQuestionAnswerNumber = (TextView) itemView.findViewById(R.id.tvQuestionAnswerNumber);
            tvQuestionFollowNumber = (TextView) itemView.findViewById(R.id.tvQuestionFollowNumber);
            tvPublishTime = (TextView) itemView.findViewById(R.id.tvPublishTime);
        }

    }

}
